local fk__gushou = fk.CreateSkill {

  name = "fk__gushou",

  tags = {  },

}

local U = require "packages/utility/utility"


fk__gushou:addEffect(fk.DamageInflicted, {
  name = "fk__gushou",
  events = {fk.DamageInflicted},
  anim_type = "defensive",
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    if not player:isNude() and player:getMark("fk__gushou_discard-turn") == 0 then table.insert(choices, "fk__gushou_discard") end
    if player.hp > 0 and player:getMark("fk__gushou_losehp-turn") == 0 then table.insert(choices, "fk__gushou_losehp") end
    if #choices == 0 then return false end
    if #choices > 1 then table.insert(choices, "Cancel") end
    local choice = room:askForChoice(player, choices, fk__gushou.name)
    if choice == "fk__gushou_discard" then
      local card = room:askForDiscard(player, 1, 1, true, fk__gushou.name, #choices == 1, ".", "#fk__gushou-discard", true)
      if #card > 0 then
        event:setCostData(self, {choice, card})
        return true
      end
    elseif choice == "fk__gushou_losehp" then
      if #choices > 1 or room:askForSkillInvoke(player, fk__gushou.name, nil, "#fk__gushou-losehp") then
        event:setCostData(self, {choice})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self)[1]
    room:addPlayerMark(player, choice.."-turn")
    if choice == "fk__gushou_discard" then
      room:throwCard(event:getCostData(self)[2], fk__gushou.name, player, player)
      if not player.dead and player:isWounded() then
        room:recover { num = 1, skillName = fk__gushou.name, who = player , recoverBy = player}
      end
    else
      room:loseHp(player, 1, fk__gushou.name)
      if not player.dead then
        player:drawCards(1, fk__gushou.name)
      end
      data:preventDamage()
    end
  end,
})

return fk__gushou